package com.appwoo.txtws.activity;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import com.appwoo.android.activity.BaseActivity;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.UserLoginComp;
import com.appwoo.txtws.service.LoginService;
import java.io.IOException;
import java.util.Random;
import org.xmlpull.v1.XmlPullParserException;

public class BindResActivity extends BaseActivity
  implements View.OnClickListener
{
  private final long TIMESET = 180000L;
  private String alertString = "";
  private String code = "no";
  Handler hanUnlock = new Handler();
  private LoginService loginService;
  private TextView text_bind;
  Thread unlockThread = new Thread()
  {
    public void run()
    {
      BindResActivity.this.code = "no";
    }
  };
  private TextView v_btn_res_back;
  private TextView v_btn_res_getcode;
  private TextView v_btn_res_reg;
  private EditText v_edit_reg_conpassword;
  private EditText v_edit_reg_password;
  private EditText v_edit_reg_phonecode;
  private EditText v_edit_reg_username;
  private EditText v_edit_res_phonenum;
  private ProgressDialog v_progressDialog;

  private void PostShowGetCode(String paramString)
  {
    if (paramString.equals("0"))
    {
      alertMessage(getString(2131427881));
      alertMessage(getString(2131427882));
      return;
    }
    if (paramString.equals("PhoneIsUsed"))
    {
      alertMessage(getString(2131427883));
      return;
    }
    alertMessage(paramString);
  }

  private void PostShowReg(String paramString)
  {
    if (paramString.equals("0"))
    {
      alertMessage(getString(2131427880));
      this.v_edit_reg_username.setText("");
      this.v_edit_reg_password.setText("");
      this.v_edit_reg_conpassword.setText("");
      this.v_edit_reg_phonecode.setText("");
      return;
    }
    alertMessage(paramString);
  }

  private void RegListener()
  {
    String str1 = this.v_edit_reg_username.getText().toString();
    String str2 = this.v_edit_reg_password.getText().toString();
    String str3 = this.v_edit_reg_conpassword.getText().toString();
    String str4 = this.v_edit_reg_phonecode.getText().toString();
    String str5 = this.v_edit_res_phonenum.getText().toString();
    if ((!str5.equals("")) && (!str2.equals("")) && (!str3.equals("")) && (!str4.equals("")))
    {
      if (str4.equals(this.code))
      {
        if (str5.length() >= 8)
        {
          if (str2.equals(str3))
          {
            if ((str1.length() > 3) && (str1.length() < 17))
            {
              if ((str2.length() > 5) && (str2.length() < 17))
              {
                new LoginAsyncTask().execute(new String[] { "reg" });
                return;
              }
              alertMessage(getString(2131427863));
              return;
            }
            alertMessage(getString(2131427864));
            return;
          }
          alertMessage(getString(2131427865));
          return;
        }
        alertMessage(getString(2131427884));
        return;
      }
      alertMessage(getString(2131427866));
      return;
    }
    alertMessage(getString(2131427879));
  }

  private void addListener()
  {
    this.v_btn_res_reg.setOnClickListener(this);
    this.v_btn_res_back.setOnClickListener(this);
    this.v_btn_res_getcode.setOnClickListener(this);
    this.text_bind.setOnClickListener(this);
  }

  private String bgReg()
  {
    this.alertString = "";
    String str1 = this.v_edit_reg_username.getText().toString();
    String str2 = this.v_edit_reg_password.getText().toString();
    String str3 = this.v_edit_res_phonenum.getText().toString();
    try
    {
      StateBean localStateBean = this.loginService.reg(str1, str2, str3, this);
      if ((localStateBean.getCode() != null) && (localStateBean.getCode().equals("0")))
        UserLoginComp.saveLoginInfo(str1, str2, getApplication());
      for (this.alertString = localStateBean.getCode(); ; this.alertString = localStateBean.getDesc())
        return this.alertString;
    }
    catch (IOException localIOException)
    {
      while (true)
        this.alertString = getString(2131427524);
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      while (true)
        this.alertString = getString(2131427524);
    }
    catch (TimeOutException localTimeOutException)
    {
      while (true)
        this.alertString = getString(2131427526);
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      while (true)
      {
        localNotFoundNetWorkException.getClass();
        this.alertString = "没有连接到网络";
      }
    }
  }

  private String getValidateCode(String paramString)
  {
    this.hanUnlock.postDelayed(this.unlockThread, 180000L);
    this.alertString = "";
    String str = this.v_edit_res_phonenum.getText().toString();
    try
    {
      StateBean localStateBean = this.loginService.sendValidateCode(str, paramString, "0", this);
      if ((localStateBean.getCode() != null) && (localStateBean.getCode().equals("0")));
      for (this.alertString = localStateBean.getCode(); ; this.alertString = "网络连接失败，请设置网络")
        return this.alertString;
    }
    catch (IOException localIOException)
    {
      while (true)
        this.alertString = getString(2131427524);
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      while (true)
        this.alertString = getString(2131427524);
    }
    catch (TimeOutException localTimeOutException)
    {
      while (true)
        this.alertString = getString(2131427526);
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      while (true)
      {
        localNotFoundNetWorkException.getClass();
        this.alertString = "没有连接到网络";
      }
    }
  }

  private void init()
  {
    this.v_btn_res_back = ((TextView)findViewById(2131492910));
    this.v_btn_res_reg = ((TextView)findViewById(2131492929));
    this.v_btn_res_getcode = ((TextView)findViewById(2131492927));
    this.text_bind = ((TextView)findViewById(2131492923));
    this.v_edit_reg_password = ((EditText)findViewById(2131492925));
    this.v_edit_reg_conpassword = ((EditText)findViewById(2131492926));
    this.v_edit_reg_phonecode = ((EditText)findViewById(2131492928));
    this.v_edit_res_phonenum = ((EditText)findViewById(2131492924));
    this.v_edit_reg_username = this.v_edit_res_phonenum;
    this.loginService = new LoginService();
  }

  private String ranNum()
  {
    String str1 = "";
    Random localRandom = new Random();
    for (int i = 0; ; i++)
    {
      if (i >= 5)
        return str1;
      String str2 = String.valueOf(localRandom.nextInt(10));
      str1 = str1 + str2;
    }
  }

  public void onClick(View paramView)
  {
    if (paramView == this.v_btn_res_reg)
    {
      RegListener();
      return;
    }
    if (paramView == this.v_btn_res_getcode)
    {
      if (this.v_edit_res_phonenum.getText().toString().length() < 8)
      {
        alertMessage(getString(2131427884));
        return;
      }
      new LoginAsyncTask().execute(new String[] { "getCode" });
      return;
    }
    backAcitvity(this);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903049);
    init();
    addListener();
  }

  protected void onDestroy()
  {
    super.onDestroy();
    try
    {
      this.hanUnlock.removeCallbacks(this.unlockThread);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public class LoginAsyncTask extends AsyncTask<String, Integer, String>
  {
    private String method = "";

    public LoginAsyncTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.method = paramArrayOfString[0];
      if (this.method.equals("reg"))
        return BindResActivity.this.bgReg();
      if (this.method.equals("getCode"))
      {
        BindResActivity.this.code = BindResActivity.this.ranNum();
        return BindResActivity.this.getValidateCode(BindResActivity.this.code);
      }
      return "";
    }

    protected void onPostExecute(String paramString)
    {
      if (this.method.equals("reg"))
        BindResActivity.this.PostShowReg(paramString);
      if (this.method.equals("getCode"))
        BindResActivity.this.PostShowGetCode(paramString);
      BindResActivity.this.v_progressDialog.dismiss();
    }

    protected void onPreExecute()
    {
      if ((BindResActivity.this.v_progressDialog == null) || (!BindResActivity.this.v_progressDialog.isShowing()))
      {
        BindResActivity.this.v_progressDialog = new ProgressDialog(BindResActivity.this);
        BindResActivity.this.v_progressDialog.setMessage(BindResActivity.this.getString(2131427516));
        BindResActivity.this.v_progressDialog.setCancelable(false);
        BindResActivity.this.v_progressDialog.show();
      }
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.BindResActivity
 * JD-Core Version:    0.6.2
 */